<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <div class="form-group">
                <label class="col-md-2 control-label">员工</label>
                <div class="col-md-10" style="width: 300px">
                    <input type="text" class="form-control" id="userId" readonly="readonly"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">开始时间</label>
                <div class="col-md-10" style="width: 200px">
                    <input type="text" class="form-control" placeholder="开始时间" id="startTime" name="startTime"
                            data-bv-notempty="true" data-bv-notempty-message="开始时间不能为空">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">结束时间</label>
                <div class="col-md-10" style="width: 200px">
                    <input type="text" class="form-control" placeholder="结束时间" id="endTime" name="endTime"
                           data-bv-notempty="true" data-bv-notempty-message="结束时间不能为空">
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-2 control-label'>请假天数</label>
                <div class='col-md-10'>
                    <input class='form-control' placeholder='请假天数' type='text' name='days' id='days'
                           data-bv-notempty='true' data-bv-notempty-message='请假天数不能为空'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-2 control-label'>请假原因</label>
                <div class='col-md-10'>
                    <textarea class='form-control' placeholder='请假原因' type='text' name='details' id='details'
                           data-bv-notempty='true' data-bv-notempty-message='请假原因不能为空'>
                    </textarea>
                </div>
            </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='leavePermitList.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="add()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../js/bootstrap/bootstrap-select.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/my/roles/role.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script type="text/javascript" src="../../js/main.js?v=1.0.0"></script>
<script type="text/javascript">
    layui.use(['layer', 'laydate', 'upload'], function () {
        var layer = layui.layer;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startTime'
        });
        laydate.render({
            elem: '#endTime'
        });

        initUser();
    });

    $('#form').bootstrapValidator();

    function add() {
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }
        var formdata = $("#form").serializeObject();
        $.ajax({
            type: 'post',
            url: '/empLeavePermit',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
                layer.msg("添加成功", {shift: -1, time: 1000}, function () {
                    location.href = "leavePermitList.html";
                });
            }
        });
    }

    function initUser() {
        var user = loginInfo();
        $("#userId").val(user.username);
    }
</script>
</body>
</html>